package com.tencent50.easy;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 爬楼梯
 * @date 2022/7/23 21:14
 */
public class Demo07 {
    public static void main(String[] args) {
        System.out.println(climbStairs1(45));

    }
    //递归栈溢出
    public static int climbStairs(int n) {

          if(n==1){
            return 1;
          }
          if(n==2){
            return 2;
         }
        return climbStairs(n-1)+ climbStairs(n-2);
    }
    public static int climbStairs1(int n) {
       int[] num=new  int[45];
       num[0]=1;num[1]=2;
        for (int i = 2; i < 45; i++) {
            num[i]=num[i-1]+num[i-2];
        }
        return num[n-1];
    }

}
